import grpc
import time

from concurrent import futures
from example import date_pb2,date_pb2_grpc

_ONE_DAY_IN_SECONDS = 60 * 60 * 24
_HOST = 'localhost'
_PORT = '8080'



class FormatData(date_pb2_grpc.FormatDataServicer):
    def Upper(self, request, context):
        word: str = request.word
        return date_pb2.UpperResponse(word=word.upper())

def server():
    grpcserver = grpc.server(futures.ThreadPoolExecutor(max_workers=4))
    date_pb2_grpc.add_FormatDataServicer_to_server(FormatData(), grpcserver)
    grpcserver.add_insecure_port(_HOST + ':' + _PORT)
    grpcserver.start()
    print("start service...")
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        grpcserver.stop(0)
